home *** CD-ROM | disk | FTP | other *** search
- // --- ctype.h testing program, written by bts 2/july/2000
-
- #include <stdio.h>
- #include <ctype.h>
- #include <assert.h>
-
- void xctype();
- int xct_punct(int c);
-
- int main()
- {
- xctype();
- }
-
-
- char clist_isdigit[128], clist_isupper[128], clist_islower[128], clist_isalpha[128],
- clist_isalnum[128], clist_isxdigit[128], clist_ispunct[128], clist_isprint[128],
- clist_isgraph[128];
-
- #define xct_add(clist,c) { char *ptr=clist; while(*ptr++) ; *ptr='\0'; *--ptr=c; }
-
- void xctype()
- {
- int i;
- char ibuf[20];
-
- printf("==> starting xctype <==\n");
-
- clist_isdigit[0]=clist_isupper[0]=clist_islower[0]=clist_isalpha[0]=
- clist_isalnum[0]=clist_isxdigit[0]=clist_ispunct[0]=clist_isprint[0]=clist_isgraph[0]= '\0';
-
- for (i=0; i<=255; i++)
- {
- // --- check isdigit
- if(i>='0' && i<='9')
- {
- assert(isdigit(i));
- xct_add(clist_isdigit,i);
- }
- else
- assert(!isdigit(i));
-
- // --- check isupper
- if(i>='A' && i<='Z')
- {
- assert(isupper(i));
- xct_add(clist_isupper,i);
- }
- else
- assert(!isupper(i));
-
- // --- check islower
- if(i>='a' && i<='z')
- {
- assert(islower(i));
- xct_add(clist_islower,i);
- }
- else
- assert(!islower(i));
-
- // --- check isalpha
- if(isupper(i) || islower(i))
- {
- assert(isalpha(i));
- xct_add(clist_isalpha,i);
- }
- else
- assert(!isalpha(i));
-
- // --- check isalnum
- if(isupper(i) || islower(i) || isdigit(i))
- {
- assert(isalnum(i));
- xct_add(clist_isalnum,i);
- }
- else
- assert(!isalnum(i));
-
- // --- check isxdigit
- if(isdigit(i) || (i>='a' && i<='f') || (i>='A' && i<='F'))
- {
- assert(isxdigit(i));
- xct_add(clist_isxdigit,i);
- }
- else
- assert(!isxdigit(i));
-
- // --- check isspace, can be 9-13 or 32
- if((i>=9 && i<=13) || i==32)
- assert(isspace(i));
- else
- assert(!isspace(i));
-
- // --- check iscntrl, can be 0-31 or 127
- if((i>=0 && i<=31) || i==127)
- assert(iscntrl(i));
- else
- assert(!iscntrl(i));
-
- // --- check ispunct
- if(xct_punct(i))
- {
- assert(ispunct(i));
- xct_add(clist_ispunct,i);
- }
- else
- assert(!ispunct(i));
-
- // --- check isgraph
- if(isalnum(i) || ispunct(i))
- {
- assert(isgraph(i));
- xct_add(clist_isgraph,i);
- }
- else
- assert(!isgraph(i));
-
- // --- check isascii
- if(i<0x80)
- assert(isascii(i));
- else
- assert(!isascii(i));
-
- // --- check isprint
- if(isgraph(i) || i==32)
- {
- assert(isprint(i));
- xct_add(clist_isprint,i);
- }
- else
- assert(!isprint(i));
- }
-
- printf("isdigit:\t%s\n",clist_isdigit);
- printf("isupper:\t%s\n",clist_isupper);
- printf("islower:\t%s\n",clist_islower);
- printf("isalpha:\t%s\n",clist_isalpha);
-
- printf("isalnum:\t%s\n",clist_isalnum);
- printf("isxdigit:\t%s\n",clist_isxdigit);
- printf("ispunct:\t%s\n",clist_ispunct);
-
- printf("isgraph:\t%s\n",clist_isgraph);
- printf("isprint:\t%s\n",clist_isprint);
-
- printf("==> finished xctype <==\n");
- return;
- }
-
- int xct_punct(int c)
- {
- // --- punc[] is an exhaustive list of all ascii punctuation characters
- char punc[] = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
- int i;
-
- for(i=0; punc[i]; i++)
- if(punc[i]==c)
- return 1;
-
- return 0;
- }
-